﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using YogaStudio.Data;
using YogaStudio.Data.Domain;

namespace YogaStudio.Service.BLL
{
   public class FacultySerivce : IFacultySerivce
   {
         private YogaStudioEntities db;
         private YogaStudioEntities _db = new YogaStudioEntities();
         public IEnumerable<WaiverRequest> GetWaiverRequestsByFacultyId(int? facultyId)
         {
             return _db.WaiverRequests.Include("Customer.User").Where(w => w.FacultyId == facultyId);
         }

         public Faculty GetFacultyByLogInUserName(string userName)
         {
             IUserManagementService userService = new UserManagementService();
             var user = userService.GetUser(userName);
             return _db.Faculties.SingleOrDefault(f => f.User.UserId == user.UserId);
         }
         public FacultySerivce()
       {
           db = new YogaStudioEntities();
       }
         public List<Faculty> GetAllFaculties()
       {
           return db.Faculties.ToList();
       }
         public Faculty GetFaculty(int id)
       {
           return db.Faculties.Find(id);

       }
       public bool DeleteFaculty(Faculty faculty)
       {
           if (faculty == db.Faculties.Remove(faculty))
           {
               db.SaveChanges();
           }
               return true;

       }
       public void UpdateFaculty(Faculty facutly)
       {
           db.Entry(facutly).State = EntityState.Modified;
          db.SaveChanges();
       }
       public void SaveFaculty(Faculty faculty)
       {
           db.Faculties.Add(faculty);
           db.SaveChanges();
       }
       public void Dispose(bool disposing)
       {
           db.Dispose();
         
       }

    }
}
